<?php

require_once('data/SugarBean.php');

class AdditionalInfo {
	function AdditionalInfo(&$bean, $event, $arguments)
	{
		global $app_list_strings, $mod_strings;
//		$bean->workload_with_units = $bean->workload.' '.$app_list_strings['task_type_units'][$bean->type];
		
		require_once('modules/edanz_Deliverables/edanz_Deliverables.php');
		$deliverable = new edanz_Deliverables();
		$deliverable->retrieve($bean->deliverable_id);
		if(!empty($deliverable)){
			$flags = $deliverable->get_linked_beans('flags', 'edanz_Flags');
			if(!empty($flags))
				$bean->has_flags = '<img border="0" src="'.SugarThemeRegistry::current()->getImageURL('flag.gif').'">';
			
			if(empty($deliverable->workload)) $deliverable->workload = 0;
			$bean->workload_with_units = $deliverable->workload.' '.$app_list_strings['service_type_units'][$deliverable->service];

			if(!empty($deliverable->origin_system) && !empty($bean->origin_module) && !empty($bean->origin_id)){
				$bean->reference = $deliverable->origin_system."/index.php?action=DetailView&module=".$bean->origin_module."&record=".$bean->origin_id;
			}
			if(!empty($deliverable->service)){
				$bean->deliverable_service = $deliverable->service;
			}
		}
		if(!empty($bean->date_start) && !empty($bean->completed_date)){
			//$seconds = strtotime(empty($bean->completed_date)?gmdate("Y-m-d H:i:s"):$bean->completed_date) - strtotime($bean->date_start) - ($bean->break_duration_hours * 60 * 60) - ($bean->break_duration_minutes * 60);
			$seconds = strtotime($bean->completed_date) - strtotime($bean->date_start) - ($bean->break_duration_hours * 60 * 60) - ($bean->break_duration_minutes * 60);
			$hours = floor($seconds / (60 * 60));
			$minutes = floor(($seconds / 60) - (floor($seconds / (60 * 60)) * 60));
			$bean->duration = $hours.$mod_strings['LBL_HOURS'].$minutes.$mod_strings['LBL_MINUTES'];
		}

/*		$query = "SELECT COUNT(*) as flags
			FROM edanz_flags, tasks 
			WHERE 
			edanz_flags.deliverable_id = tasks.deliverable_id
			AND
			tasks.id = '".$bean->id."'";
		$result = $bean->db->query($query);
		$row    = $bean->db->fetchByAssoc($result);
		if (!empty($row) && $row['flags']>0) {
			$bean->has_flags = '<img border="0" src="'.SugarThemeRegistry::current()->getImageURL('flag.gif').'">';
		}
*/
		
/*
		$query = "select first_name, last_name, related_editor_id from users, tasks where users.id = tasks.related_editor_id and tasks.id ='".$bean->id."'";
                $result = $bean->db->query($query);
                if ( $row = $bean->db->fetchByAssoc($result) )
                {
                        $bean->related_editor_name = $row['first_name'].' '.$row['last_name'];
                        $bean->related_editor_id = $row['related_editor_id'];
                }
*/
	}
}

?>
